
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="com.pay.sdk.*"%>
<%@ page import="java.text.*"%>
<%@ page import="java.util.*"%>
<%@ page import="com.pay.sdk.service.channel2.*"%>
<%@ page import="com.alibaba.fastjson.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>微信公众号支付接口</title>
<script src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
</head>
<%
	////////////////////////////////////请求参数//////////////////////////////////////

	//商户订单号
	String out_trade_no = new String(request.getParameter("total_fee").getBytes("ISO-8859-1"), "UTF-8") != null
			? new String(request.getParameter("total_fee").getBytes("ISO-8859-1"), "UTF-8")
			: new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
	//付款金额
	String total_fee = new String(request.getParameter("total_fee").getBytes("ISO-8859-1"), "UTF-8"); //单位分
	String body = new String(request.getParameter("body").getBytes("ISO-8859-1"), "UTF-8");
	String device_info = "wap";
	String time_expire = "1440";
	String acquirer_type = "wechat";
	String bank_card_limit = "2";//支付卡类型：1-储蓄卡 2储蓄卡和信用卡
	String appid = "wxd1732e33689bd7d4";//微信公众号appId
	String openid = "oM4YVs6DpFBXteF3MBZEu31c5aDU";//上面公众号对应的用户openid
	//服务器异步通知页面路径
	String notify_url = new String(request.getParameter("notify_url").getBytes("ISO-8859-1"), "UTF-8");

	//////////////////////////////////////////////////////////////////////////////////

	String result = ChanneTwolPay.h5Pay(out_trade_no, total_fee, body, device_info, notify_url, acquirer_type,
			bank_card_limit, time_expire,appid,openid);

	JSONObject jsonObj = JSONObject.parseObject(result);
	String status = jsonObj.getString("status");
	String message = jsonObj.getString("message");
	String err_msg = jsonObj.getString("err_msg");
	String code_url = jsonObj.getString("code_url");
	String pay_info = jsonObj.getString("pay_info");
	
	JSONObject payInfo = JSONObject.parseObject(pay_info);
	String appId = payInfo.getString("appId");
	String timeStamp = payInfo.getString("timeStamp");
	String signType = payInfo.getString("signType");
	String prepay_id = payInfo.getString("package");
	String nonceStr = payInfo.getString("nonceStr");
	String paySign = payInfo.getString("paySign");
	/* out.print("<script>alert('" + pay_info + "');</script>"); */
%>
<body>

<script type="text/javascript">
function onBridgeReady(){
	WeixinJSBridge.invoke(
	       'getBrandWCPayRequest', {
	           "appId":"<%=appId%>",     //公众号名称，由商户传入     
	           "timeStamp":"<%=timeStamp%>",         //时间戳，自1970年以来的秒数     
	           "nonceStr":"<%=nonceStr%>", //随机串     
	           "package":"<%=prepay_id%>",     
	           "signType":"<%=signType%>",         //微信签名方式：     
	           "paySign":"<%=paySign%>" //微信签名 
	       },
	       function(res){     
	           if(res.err_msg == "get_brand_wcpay_request:ok" ) {
	        	   window.location = "wx_test_index.jsp";
	           }     // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。 
	       }
	   ); 
	}
	if (typeof WeixinJSBridge == "undefined"){
	   if( document.addEventListener ){
	       document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
	   }else if (document.attachEvent){
	       document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
	       document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
	   }
	}else{
	   onBridgeReady();
	}
</script>
</body>
</html>
